﻿@model UniTax.Models.TaxiList
<div id="town_ @Model.Town.Id">
    <strong>Актуальность обновлений: @Model.Town.LastUpd</strong>
    <p>
        @Ajax.ActionLink("Добавить новую службу такси", "TaxiCreate", new { townId = Model.Town.Id }, new AjaxOptions
   {
       UpdateTargetId = "ajaxContainer",
       OnBegin = "showWaitDiv",
       OnSuccess = "hideWaitDiv"
   }, new { @class = "ico add" })
    </p>
    <table class="table hovertable">
        <tr>
            <th>Наименование службы такси</th>
            <th>Лицензия действительна до</th>
            <th>Телефоны</th>
            <th>Контактные телефоны</th>
            <th></th>
        </tr>

        @foreach (var taxi in Model.Taxis.Where(taxi => taxi.TownId == Model.Town.Id))
        {
            //Проверка лицензии
            ViewBag.Color = taxi.License < DateTime.Now ? "red" : "green";
                
            <tr class="@ViewBag.Color">
                <td>
                    @Html.DisplayFor(modelItem => taxi.Name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => taxi.License)
                </td>
                <td>
                    @foreach (var phone in taxi.Phones)
                    {
                        <p>@phone.Phone1</p>
                    }
                </td>
                <td>
                    @foreach (var phone in taxi.ContactPhones)
                    {
                        <p>@phone.Phone</p>
                    }
                </td>
                <td>
                    @Ajax.ActionLink("Подробнее", "TaxiDetails", new { id = taxi.Id }, new AjaxOptions
                        {
                            UpdateTargetId = "ajaxContainer",
                            OnBegin = "showWaitDiv",
                            OnSuccess = "hideWaitDiv"
                        }, new { @class = "ico details" })
                    <br />
                    @Ajax.ActionLink("Редактировать", "TaxiEdit", new { id = taxi.Id }, new AjaxOptions
                        {
                            UpdateTargetId = "ajaxContainer",
                            OnBegin = "showWaitDiv",
                            OnSuccess = "hideWaitDiv"
                        }, new { @class = "ico edit" })
                    <br />
                    @Ajax.ActionLink("Удалить", "TaxiDelete", new { id = taxi.Id }, new AjaxOptions
                        {
                            UpdateTargetId = "ajaxContainer",
                            OnBegin = "showWaitDiv",
                            OnSuccess = "hideWaitDiv"
                        }, new { @class = "ico del" })
                </td>
            </tr>
        }
    </table>
</div>
